'use strict'

define([ 'jquery', 'bootstrap', 'select2', 'shiftform', 'validate',
        'validate.en' ], function($) {
    return {
        init : function() {
            this.initEdit();
            this.initDelete();
            this.initCreate();
         
        },

        initEdit : function() {

            $(document).on('shown.bs.modal', '#edit', function(e) {

            	$('select[name="type"]').change(function() {
                    var role = $(this).val()
                    if(role == 0) {
                        $('.department').addClass('hide')
                    } else {
                        $('.department').removeClass('hide')
                    }
                })
            	
                $(document).find('form[data-validate="true"]').bt_validate() // bind
                                                                                // validate

                var $form = $(document).find("form") // bind shiftform
                $form.shiftform({
                    beforeSubmit : function(el) {
                        $form.trigger("validate.ajax.submit");
                        return $.bt_validate.result[$.bt_validate.form_id]
                    }
                })
            });

        },
        initDelete : function() {

            $(document).on('shown.bs.modal', '#delete', function(e) {

            	$('select[name="type"]').change(function() {
                    var role = $(this).val()
                    if(role == 0) {
                        $('.department').addClass('hide')
                    } else {
                        $('.department').removeClass('hide')
                    }
                })
            	
                $(document).find('form[data-validate="true"]').bt_validate() // bind

                var $form = $(document).find("form") // bind shiftform
                $form.shiftform({
                    beforeSubmit : function(el) {
                        $form.trigger("validate.ajax.submit");
                        return $.bt_validate.result[$.bt_validate.form_id]
                    }
                })
            });

        },
         initCreate : function() {

            $(document).on('shown.bs.modal', '#create', function(e) {

            	$('select[name="type"]').change(function() {
                    var role = $(this).val()
                    if(role == 0) {
                        $('.department').addClass('hide')
                    } else {
                        $('.department').removeClass('hide')
                    }
                })
            	
                $(document).find('form[data-validate="true"]').bt_validate() // bind

                var $form = $(document).find("form") // bind shiftform
                $form.shiftform({
                    beforeSubmit : function(el) {
                        $form.trigger("validate.ajax.submit");
                        return $.bt_validate.result[$.bt_validate.form_id]
                    }
                })
            });

        }
       
        
    }
})
